package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.io.File;

@Configuration
public class PathConfig extends WebMvcConfigurationSupport {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //addResourceHandler = url请求的路径   //addResourceLocations=图片存放在服务器的真实路径
        String path = System.getProperty("user.dir") + File.separator + "file" + File.separator;
        registry.addResourceHandler("/file/**").addResourceLocations("file:" + path);
//        registry.addResourceHandler("/file/**").addResourceLocations("file:E:\\code\\javaspring\\gitee\\file\\"); //例子
    }
}
